package cn.airfei.netty.nio.zerocopy;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * @description:
 * @author: air
 * @create: 2021-01-15 14:21
 */
public class NewIOClient {
    public static void main(String[] args) throws IOException {

        SocketChannel socketChannel = SocketChannel.open();
        boolean connect = socketChannel.connect(new InetSocketAddress("127.0.0.1", 7002));
        System.out.println("connect:"+connect);
        // 准备发送
        long startTime = System.currentTimeMillis();
        String fileName="/home/air/Downloads/air3132268206-ff-wx-master.zip";

        FileChannel fileChannel = new FileInputStream(fileName).getChannel();



        long transferTo = fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        System.out.println("发送总字节数:"+transferTo+",耗时:"+(System.currentTimeMillis()-startTime));

        fileChannel.close();
    }

}
